home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
EnigmA Amiga Run 1995 November
/
EnigmA AMIGA RUN 02 (1995)(G.R. Edizioni)(IT)[!][issue 1995-11][Skylink CD].iso
/
earcd
/
util
/
text
/
crlf2lf.lha
/
CRLF2LF.c
< prev
next >
Wrap
C/C++ Source or Header
|
1995-09-06
|
2KB
|
96 lines
*/
* Original source by Krzysztof Sporysz vel Kivi 06-sep-95
* Small, Fast and simple CRLF to LF converter
*/
#include <dos/dos.h>
#include <stdio.h>
#include <stdlib.h>
#include <functions.h>
#include <exec/exec.h>
#define HELP "Usage: infile outfile"
#define BUF 1024*32
char __stdiowin[]= "CON:0/20/320/80/CRLF2LF v1.0 by Kiviks";
char __stdiov37[]= "/AUTO/CLOSE/WAIT";
BPTR infile,outfile;
char in[BUF+1];
char out[BUF+1];
int j;
void error(int deep, char kom[])
{
switch(deep)
{
case 2:
{
Close(outfile);
}
case 1:
{
Close(infile);
}
case 0:
{
printf("%s\n",kom);
exit(0);
break;
}
}
}
void convert(int leng)
{
int i,offset=0;
for(i=0;(i+offset)<leng;i++)
{
if(in[i+offset]!=13)
{
out[j]=in[i+offset];
j++;
if(j>=BUF) Write(outfile,out,BUF),j=0;
}
else
{
if(in[i+offset+1]=10)
{
out[j]=10;
j++;
if(j>=BUF)
{
Write(outfile,out,BUF);
j=0;
}
offset++;
}
}
}
}
void main(int argc,char *argv[] )
{
long bytes_read=BUF,i;
if(argc != 3) error(0,HELP);
printf("In File :%s\nOut File :%s\n",argv[1],argv[2]);
infile=Open(argv[1],MODE_OLDFILE);
if(!infile) error(0,"In File couldn't be opened.");
outfile=Lock(argv[2],EXCLUSIVE_LOCK);
if(outfile)
{
UnLock(outfile);
error(1,"Out File exist. Can't overwrite.");
}
outfile=Open(argv[2],MODE_NEWFILE);
j=0;
while(bytes_read==BUF)
{
bytes_read=Read(infile,in,BUF+1);
convert(bytes_read-1);
bytes_read--;
Seek(infile,-1,OFFSET_CURRENT);
}
if(j>0 && j<=BUF)
{
Write(outfile,out,j);
}
error(2,"Success !!!");
}